package com.zhao.eduservice.controller;


import com.zhao.commonutils.R;
import com.zhao.eduservice.entity.subject.OneSubject;
import com.zhao.eduservice.service.EduSubjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * <p>
 * 课程科目
 * </p>
 *
 * @author test_java
 * @since 2022-10-14
 */
@RestController
@RequestMapping("/eduservice/subject")
// 解决跨域问题
@CrossOrigin
public class EduSubjectController {

    @Autowired
    private EduSubjectService eduSubjectService;

    // 添加课程分类
    // 获取上传的excel文件 读取文件内容
    @PostMapping("addSubject")
    public R addSubject(MultipartFile file) {
        // 获取上传的excel文件
        eduSubjectService.saveSubject(file, eduSubjectService);
        return R.ok();
    }

    // 课程分类列表（树形）
    @GetMapping("getAllSubject")
    public R getAllSubject() {
        // 返回一级分类 一级分类包含二级分类
        List<OneSubject> list = eduSubjectService.getAllSubject();
        return R.ok().data("list",list);
    }
}

